package edu.dao;

import edu.domain.Person;

import java.util.ArrayList;

public class BasePersonDaoImpl<E> implements PersonDao<E> {
    public ArrayList<E> list = new ArrayList<>();
    {
        E e1 = (E)new Person("root","超级管理员","2021-11-28","0");
        E e2 = (E)new Person("admin","管理员","2021-11-28","0");
        list.add(e1);
        list.add(e2);
    }
    @Override
    public void addPerson(E e) {
        list.add(e);
    }

    @Override
    public void delectPerson(int index) {
        list.remove(index);
    }

    @Override
    public void updatePerson(int index, E e) {
        list.set(index,e);
    }

    @Override
    public ArrayList<E> findAllPerson() {
        return list;
    }

    @Override
    public int getIndexById(String id) {
        for (int i = 0; i < list.size(); i++) {
            E e = list.get(i);
            Person p = (Person) e;
            if (p.getId().equals(id)) {
                return i;
            }
        }
        return -1;
    }
}
